package com.xmut.mall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.xmut.mall.product.annotation.CheckJwt;
import com.xmut.mall.product.utils.RespBean;
import com.xmut.mall.product.vo.AddBrandVo;
import com.xmut.mall.product.vo.EditBrandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xmut.mall.product.entity.BrandEntity;
import com.xmut.mall.product.service.BrandService;
import com.xmut.mall.product.utils.PageUtils;
import com.xmut.mall.product.utils.R;



/**
 * 品牌
 *
 * @author 1912120131suntingxing
 * @email 1192081604@qq.com
 * @date 2022-07-14 00:45:34
 */
@RestController
@RequestMapping("product/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 删除品牌
     * @param brandId
     * @return
     */
    @CheckJwt
    @DeleteMapping("/deleteBrand/{brandId}")
    public RespBean deleteBrand(@PathVariable Long brandId){
        return brandService.deleteBrand(brandId);
    }

    /**
     * 启用该品牌
     * @param brandId
     * @return
     */
    @CheckJwt
    @PutMapping("/enableBrand/{brandId}")
    public RespBean enableBrand(@PathVariable Long brandId){
        return brandService.enableBrand(brandId);
    }

    /**
     * 禁用品牌
     * @param brandId
     * @return
     */
    @CheckJwt
    @PutMapping("/disableBrand/{brandId}")
    public RespBean disableBrand(@PathVariable Long brandId){
        return brandService.disableBrand(brandId);
    }

    /**
     * 修改品牌信息
     * @param vo
     * @return
     */
    @CheckJwt
    @PutMapping("/editBrand")
    public RespBean editBrand(@RequestBody EditBrandVo vo){
        return brandService.editBrand(vo);
    }

    /**
     * 添加品牌
     * @param vo
     * @return
     */
    @CheckJwt
    @PostMapping("/addBrand")
    public RespBean addBrand(@RequestBody AddBrandVo vo){
        return brandService.addBrand(vo);
    }

    /**
     * 获取品牌分页数据
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/getBrandPage")
    public RespBean getBrandPage(@RequestBody Map<String,Object> params){
        return brandService.getBrandPage(params);
    }

    /**
     * 根据分类的id获取与其关联的品牌
     * @param cateId
     * @return
     */
    @GetMapping("/getBrandByCateId/{cateId}")
    public RespBean getBrandByCateId(@PathVariable Long cateId){
        List<BrandEntity> brands = brandService.getBrandByCateId(cateId);
        return RespBean.success("获取品牌成功",brands);
    }

    /**
     * 获取全部品牌
     * @return
     */
    @CheckJwt
    @GetMapping("/getAllBrand")
    public RespBean getAllBrand(){
        List<BrandEntity> list = brandService.getAllBrand();
        return RespBean.success("获取成功",list);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = brandService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    public R info(@PathVariable("brandId") Long brandId){
		BrandEntity brand = brandService.getById(brandId);

        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BrandEntity brand){
		brandService.save(brand);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody BrandEntity brand){
        brandService.updateDetail(brand);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] brandIds){
		brandService.removeByIds(Arrays.asList(brandIds));

        return R.ok();
    }

}
